package com.free.semantic.core.common.serializeimpl.baseimpl;

import com.alibaba.fastjson.JSONObject;
import com.free.semantic.common.RelationItem;
import com.free.semantic.core.RelationFunction;
import com.free.semantic.core.common.serializeimpl.BaseSerializeImpl;
import com.free.semantic.core.funcimpl.MultipleKeyFuncImpl;
import com.free.semantic.core.funcimpl.MultipleKeyMap;
import org.springframework.stereotype.Component;

@Component
public class MultipleKeyFuncMap implements BaseSerializeImpl {

    private MultipleKeyMap keyResMap;

    private String[] source;

    private String dest;

    public MultipleKeyFuncMap(MultipleKeyFuncImpl impl) {
        this.keyResMap = impl.getKeyResMap();
        this.source = impl.getSource();
        this.dest = impl.getDest();
    }

    public MultipleKeyFuncMap() {
    }

    @Override
    public JSONObject getParameter() {
        JSONObject parameter = new JSONObject();
        parameter.put("source", source);
        parameter.put("dest", dest);
        parameter.put("keyResMap", JSONObject.toJSONString(keyResMap));
        return parameter;
    }

    @Override
    public RelationFunction fromParam(JSONObject parameter) {
        String[] object = (String[]) parameter.get("source");
        String dest = parameter.getString("dest");
        MultipleKeyMap keyResMap = JSONObject.parseObject(parameter.getString("keyResMap"), MultipleKeyMap.class);
        return new MultipleKeyFuncImpl(object, dest, keyResMap);
    }

}
